const jwt = require('jsonwebtoken')
const config = require('../config/auth.config.js')
const login = (ctx) => {
    const { username, password } = ctx.request.body
    if (username === 'admin' && password === '123456') {
        // 给request 颁发一个 2. 凭证
            // 1. session 会话对象 JSON cookie sid 每次带上sid
            // session 会解析 cookie sid 
        const token = jwt.sign({uid: 131456}, config.secret, {
            expiresIn: 86400
        }) // 签发凭证
        console.log(token);
        ctx.body = {
            code: 0,
            token,
            message: '登录成功'
        }
    } else {
        ctx.body = {
            code: -1,
            message: '账号或密码错误'
        }
    }
    console.log(ctx.request.body)
    ctx.body = `登录成功`
}

module.exports = {
    login
}